package org.kernely.directory.userpage;

import java.io.Serializable;
import java.util.Comparator;

import org.kernely.security.persistence.UserDetails;

	/**
	 * The comparator for Messages, to order them by ID.
	 */
	@SuppressWarnings("serial")
	public class NameComparator implements Comparator<UserDetails>, Serializable{

		/**
		 * Compares two users by their name and then first name. Case insensitive.
		 * @param details1 Details from a user.
		 * @param details2 Details from another user.
		 * @return a negative integer if the first details are inferior to the second, a positive one otherwise.
		 */
		public final int compare(UserDetails details1, UserDetails details2) {
			// Compare by name
			int result = details1.getName().compareToIgnoreCase(details2.getName());

			// If names are equals, compare by firstname
			if (result == 0){
				result = details1.getFirstname().compareToIgnoreCase(details2.getFirstname());
			}
			
			return result;
		}
		
	}